package org.lmw.note.adapter;

import java.util.List;

import org.lmw.note.Note;
import org.lmw.note.R;

import com.norbsoft.typefacehelper.TypefaceHelper;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class NoteAdapter extends BaseAdapter {
	LayoutInflater inflater;
	List<Note> rs;
	int[] colors={R.color.holo_green_light,R.color.holo_blue_light,R.color.holo_orange_light,R.color.holo_red_light,R.color.holo_purple};
	public NoteAdapter(Context c,List<Note> rs) {
		inflater=LayoutInflater.from(c);
		this.rs=rs;
	}

	@Override
	public int getCount() {
		return rs.size();
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView==null){
			convertView=inflater.inflate(R.layout.item_note, parent,false);
			TypefaceHelper.typeface(convertView);
		}
		convertView.findViewById(R.id.head).setBackgroundResource(colors[position%colors.length]);
		Note n=rs.get(position);
		((TextView)convertView.findViewById(R.id.text)).setText(n.getText());
		((TextView)convertView.findViewById(R.id.date)).setText(n.getCreateTime().substring(5, 17));
		
		
		return convertView;
	}

}
